package IO.g3;

import java.io.IOException;
import java.io.RandomAccessFile;


public class RandomAccess {

	public static void main(String[] args) throws IOException {
	
		Student s1 = new Student("Herbert",123,"Medizin");
		
		int entrySize = 20;
		RandomAccessFile ra = new RandomAccessFile("randomAccess.txt", "rw");
	
		int i = 0;	
		//ra.seek(i * entrySize);
		ra.writeChars(s1.getName());
		ra.seek(++i * entrySize);
		//ra.writeChar(':');
		//ra.seek(++i * entrySize);
		ra.writeInt(s1.getStudyID());
		ra.seek(++i * entrySize);
		//ra.writeChar(':');
		//ra.seek(++i * entrySize);
		ra.writeChars(s1.getDepartment());
		ra.seek(++i * entrySize);
		ra.writeChars(System.getProperty("line.separator"));
			
		ra.seek(entrySize);
		int studyID = ra.readInt();
		System.out.println(studyID);
		
		ra.seek(2*entrySize);
		String department = "";
		char chr = 0;
		while((chr = ra.readChar()) != 0){
			department += chr;
		}
		System.out.println(department);
		
		
		
		
	}

}
